﻿'use strict';

app.controller('ProfileController', ['$scope', 'userService',
    function ($scope, userService) {
        $scope.header = {
            title: "Profile",
            iconUrl: "#/home",
            icon: 'icon-home'
        };
        $scope.username = userService.getUsername();

        $scope.$watch('username', function() {
            userService.saveUsername($scope.username);
        });

        $scope.takePicture = function () {
            navigator.camera.getPicture(function(imageBase64) {
                var photo = "data:image/jpeg;base64," + imageBase64;
                window.confirm = navigator.notification.confirm;
                navigator.notification.confirm(
                    'Do you want to change your current picture!', // message
                     function (buttonIndex) // callback to invoke with index of button pressed
                     {
                         if (buttonIndex == 2) { // Clicked sure
                             userService.saveUserPicture(imageBase64);
                         }
                     },
                    'Override current?',  // title
                    'Sure,Exit'         // buttonLabels
                );
            }, function(error) {
                alert('Failed because: ' + error);
            }, {
                quality: 50,
                destinationType: 0,
                sourceType: Camera.PictureSourceType.CAMERA,
                allowEdit: false,
                encodingType: Camera.EncodingType.JPEG,
                targetWidth: 200,
                targetHeight: 200,
                popoverOptions: CameraPopoverOptions,
                saveToPhotoAlbum: false
            });
        };
}]);